-- desert_altar
-- created by panyl
-- 地牢格子：沙漠祭坛

return {
    restoreGrid = function(grid, info)
        -- 还原状态
        grid.submit_state = info["submit_state"] or 0;
    end,

    collectContext = function(grid)
        -- 收集
        return { ["submit_state"] = grid.submit_state or 0, };
    end,

    -- 自动战斗
    autoFight = function(grid)
        -- 可以提交的ID
        local canSubmit = {};
        for i = 1, 3 do
            if DesertAltarM.canSubmit(i) then
                table.insert(canSubmit, i);
            end
        end

        if #canSubmit <= 0 then
            return false;
        end

        -- 随机选一个选项
        local randomId = canSubmit[math.random(#canSubmit)];
        if DesertAltarM.canSubmit(randomId) then
            local options = grid.options[randomId];
            local optionId = options[math.random(#options)];
            local data = bit.blshift(randomId, 16) + optionId;

            return DungeonActionM.go("desert_altar", grid:getPos(), data);
        end
    end
};
